﻿using Md.Api.Model;
using Md.Api.Model.Manage.SysUser.Request;
using Md.Api.Service.Manage.SysUser;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Md.Api.Controllers.Manage;
/// <summary>
/// 系统用户
/// </summary>
[ApiController]
[Produces("application/json")]
[Route("md-api/manage/system/user")]
public class SysUserController : ControllerBase
{
    /// <summary>
    /// 系统用户登录服务
    /// </summary>
    public SysUserLoginService sysUserLoginService { get; set; }
    /// <summary>
    /// 系统用户登录
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("login"), HttpPost, AllowAnonymous]
    public async Task<ResponseMessageModel> SysUserLogin([FromBody] RequestSysUserLoginModel model)
    {
        return await Task.Run(() => sysUserLoginService.Execute(model));
    }

    /// <summary>
    /// 通过用户编号删除系统用户服务
    /// </summary>
    public DeleteSysUserByUserIdService deleteSysUserByUserIdService { get; set; }
    /// <summary>
    /// 通过用户编号删除系统用户
    /// </summary>
    /// <param name="userIds">用户编号多个逗号分割（1,2,3...）</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpDelete("{userIds}")]
    public async Task<ResponseMessageModel> DeleteSysUserByUserId(string userIds, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestDeleteSysUserByUserIdModel();

        model.UserIds = userIds;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => deleteSysUserByUserIdService.Execute(model));
    }

    /// <summary>
    /// 添加系统用户服务
    /// </summary>
    public InsertSysUserService insertSysUserService { get; set; }
    /// <summary>
    /// 添加系统用户
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPost]
    public async Task<ResponseMessageModel> InsertSysUser([FromBody] RequestInsertSysUserModel model)
    {
        return await Task.Run(() => insertSysUserService.Execute(model));
    }

    /// <summary>
    /// 通过用户编号更新系统用户服务
    /// </summary>
    public UpdateSysUserByUserIdService updateSysUserByUserIdService { get; set; }
    /// <summary>
    /// 通过用户编号更新系统用户
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPut]
    public async Task<ResponseMessageModel> UpdateSysUserByUserId([FromBody] RequestUpdateSysUserByUserIdModel model)
    {
        return await Task.Run(() => updateSysUserByUserIdService.Execute(model));
    }

    /// <summary>
    /// 修改系统用户密码服务
    /// </summary>
    public ForgetSysUserPwdService forgetSysUserPwdService { get; set; }
    /// <summary>
    /// 修改系统用户密码
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("forget/pwd"), HttpPut]
    public async Task<ResponseMessageModel> ForgetSysUserPwd([FromBody] RequestForgetSysUserPwdModel model)
    {
        return await Task.Run(() => forgetSysUserPwdService.Execute(model));
    }

    /// <summary>
    /// 重置系统用户密码服务
    /// </summary>
    public ResetSysUserPwdService resetSysUserPwdService { get; set; }
    /// <summary>
    /// 重置系统用户密码
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("reset/pwd"), HttpPut]
    public async Task<ResponseMessageModel> ResetSysUserPwd([FromBody] RequestResetSysUserPwdModel model)
    {
        return await Task.Run(() => resetSysUserPwdService.Execute(model));
    }

    /// <summary>
    /// 通过系统用户编号获取系统用户信息服务
    /// </summary>
    public GetSysUserByUserIdService getSysUserByUserIdService { get; set; }
    /// <summary>
    /// 通过系统用户编号获取系统用户信息
    /// </summary>
    /// <param name="userId">用户编号</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpGet("{userId}")]
    public async Task<ResponseMessageModel> GetSysUserByUserId(long userId, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestGetSysUserByUserIdModel();

        model.UserId = userId;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => getSysUserByUserIdService.Execute(model));
    }

    /// <summary>
    /// 获取系统用户列表服务
    /// </summary>
    public GetSysUserListService getSysUserListService { get; set; }
    /// <summary>
    /// 获取系统用户列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("list"), HttpPost]
    public async Task<ResponseMessageModel> GetSysUserList([FromBody] RequestGetSysUserListModel model)
    {
        return await Task.Run(() => getSysUserListService.Execute(model));
    }

    /// <summary>
    /// 分页获取系统用户列表服务
    /// </summary>
    public GetSysUserPageListService getSysUserPageListService { get; set; }
    /// <summary>
    /// 分页获取系统用户列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("listPage"), HttpPost]
    public async Task<ResponseMessageModel> GetSysUserPageList([FromBody] RequestGetSysUserPageListModel model)
    {
        return await Task.Run(() => getSysUserPageListService.Execute(model));
    }
}

